package com.enation.app.javashop.core.client.fallback.member;

import com.enation.app.javashop.core.client.feignimpl.member.MemberClientFeigntImpl;
import com.enation.app.javashop.core.handler.BaseFallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.enation.app.javashop.model.member.dos.Member;
import com.enation.app.javashop.model.member.dos.MemberCoupon;
import com.enation.app.javashop.model.member.dos.MemberPointHistory;
import com.enation.app.javashop.model.member.vo.BackendMemberVO;
import com.enation.app.javashop.model.security.ScanModuleDTO;
import com.enation.app.javashop.model.security.ScanResult;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 会员相关熔断fallback factory
 * @author kingapex
 * @version 1.0
 * @data 2022/5/28 14:25
 **/
@Component
public class MemberClientFallbackFactory extends BaseFallbackFactory<MemberClientFeigntImpl> {
    @Override
    protected MemberClientFeigntImpl fallback() {
        return new MemberClientFallback();
    }

    /**
     * 会员相关熔断
     *
     * @author zh
     * @version v7.0
     * @date 18/9/27 下午3:44
     * @since v7.0
     */
    @Component
    public static class MemberClientFallback implements MemberClientFeigntImpl {

        private final Logger logger = LoggerFactory.getLogger(getClass());


        @Override
        public Member getModel(Long memberId) {
            logger.error("获取会员ID为" + memberId + "信息错误");
            return null;
        }

        @Override
        public void loginNumToZero() {
            logger.error("会员登录数清空错误");
        }

        @Override
        public Member edit(Member member, Long id) {
            logger.error("修改会员ID为" + id + "的信息错误");
            return null;
        }

        @Override
        public void pointOperation(MemberPointHistory memberPointHistory) {
            logger.error("会员积分操作错误");
        }

        @Override
        public List<String> queryAllMemberIds() {
            logger.error("查询所有的会员id错误");
            return null;
        }

        @Override
        public MemberCoupon getModel(Long memberId, Long mcId) {
            logger.error("读取会员ID为" + memberId + "的优惠券错误");
            return null;
        }

        @Override
        public void usedCoupon(Long mcId, String orderSn) {
            logger.error("使用优惠券发生异常，优惠券id" + mcId + "，订单："+orderSn);
        }

        @Override
        public void receiveBonus(Long memberId, String memberName, Long couponId) {
            logger.error("获得优惠券发生异常，优惠券id" + couponId + "，会员id："+memberId);
        }

        @Override
        public List<BackendMemberVO> newMember(Integer length) {
            logger.error("查询新的会员错误");
            return null;
        }

        @Override
        public ScanResult scanModule(ScanModuleDTO scanModuleDTO) {
            logger.error("会员服务调用失败，scanModule");
            return null;
        }

        @Override
        public void reSign() {
            logger.error("会员服务调用失败，reSign");
        }

        @Override
        public void repair(Long memberId) {
            logger.error("会员服务调用失败，repair");
        }

        @Override
        public void sleepMember(long timeStamp) {
            logger.error("会员服务调用失败，sleepMember");
        }

        @Override
        public void updateLoginNum(Long memberId, Long now) {
            logger.error("修改会员登录次数错误，会员为ID" + memberId);
        }
    }
}
